Highlight an enumeration attribute cell (text or background)

Hi!

I have a trigger, that changes one enumeration attribute (from released to draft), what is working fine.

My problem is, that I have to highlight that it has changed somehow.

 

Example:

Object Text: Bla    Status_Attribute:Released

(now s.o. changes Object Text and the trigger fires and changes Status_Attribute to Draft)

Object Text: Bla_Change    Status_Attribute(set by trigger):Draft

Is it possible to highlight the Status_Attribute (only in this Object) somehow?

With best regards,
Bjoern

 

PS: Here is my code:


string DXLCode2 = "
 Trigger    trg = current;          
 if (null trg) halt();
 AttrDef ad  = attrdef(trg);
 if (null ad) halt();  // Error?
 Object  obj = object(trg); 
 if (null obj) halt();  // Error?
 string  Name = ad.name;  
 
 Module mod = module(trg);
 
 // Trigger feuert auch im read mode, wenn
 // man das Objekt doppelklickt, daher...
 if(!isEdit(mod)&&!isShare(mod)) halt();
 
 if(Name == \"Object Text\")
 {  
  for ad in mod do
  {
   if(ad.object)
    {
    if(ad.description \"\" == \"Variant Status\")
    {
     string BB_Variant_name=ad.name;    
     if(obj.BB_Variant_name \"\" == \"Released\")
     {
      obj.BB_Variant_name = \"Draft\";
     }
    }
   }
  }
 }
";

 

Trigger trg2;
bool    TrigOK2 = true;
string  ErrMess2 = checkDXL(DXLCode2);

if (!null ErrMess2)
{
   print ErrMess2 "\n***********\n" DXLCode2 "**********\n"
   TrigOK2       = false
}

string  NameTrig2 = "PostEditTrigger"
string Prompt2 = "Delete trigger '" NameTrig2 "' ??"
if (!TrigOK2) Prompt2 = "Trigger code has errors.\n" Prompt2
if (confirm(Prompt2))
{
   ErrMess = delete (NameTrig2, module->object->attribute, post, modify, 7);
}
 
if (TrigOK2 && confirm("Deploy trigger '" NameTrig2 "' ??"))
{
   trg2     = trigger(NameTrig2, module->object->attribute, post, modify, 7, DXLCode2);
   infoBox "Installation complete!";
}

 


Bjoern_Karpenstein - Tue Sep 22 07:27:03 EDT 2015

Re: Highlight an enumeration attribute cell (text or background)
Richard_Hesketh - Fri Sep 25 05:42:16 EDT 2015

The only way I have found to do this is to populate another attribute using DXL. Obviously this doesn't scale well, but if you're only doing it for one or two attributes, it may be acceptable.

Outline method:

  1. Create a colour-coded, enumerated attribute "c".
  2. Get date & time when module was last opened (session history search) "a".
  3. Get date & time when the desired attribute was last modified (object history search) "b".
  4. If b>a, set value of c accordingly.

It's long-winded if you try to do it rigorously, but I created a partial solution (designed to work on current object, so it should be easy to modify to run on an object trigger) some time ago. It creates a 'monitor' attribute (and associated type) automatically, and sets them according to changes in the attribute declared as variable STR_SUBJECT_ATTRIBUTE. Hope it helps - usual caveats about bespoke code; this is incomplete, not as rigorous as it should be, doesn't clean up the type/attr when no longer required, etc...

//<highlightChangedObj.dxl>

/*
Program Description
*/

/*
Licensed Materials - Property of IBM - some unique copyrights (i.e., the ability
to copy, modify, distribute) may be licensed in certain circumstances
(e.g., sample/template code intended to be used by customers to build upon and
distribute as their own products).

(c) Copyright IBM Corporation 2010. All Rights Reserved.

U.S. Government Users Restricted Rights: Use, duplication or disclosure restricted
by GSA ADP Schedule Contract with IBM Corp.
*/


//////////////////////////////////////
// Pragmas

// pragma runLim, 0


//////////////////////////////////////
// Constant/Variable Declarations

const bool BL_DEBUG = true // Set false to eliminate 'print' statements
Object obj = current // FOR TESTING OUTSIDE TRIGGER/ATTR/LAYOUT DXL CONTEXT ONLY!

const string STR_SUBJECT_ATTRIBUTE           = "Status"
const string STR_MONITOR_ATTRIBUTE           = "ZZZ_Monitor_Attr_" STR_SUBJECT_ATTRIBUTE
const string STR_MONITOR_ATTRIBUTE_TYPE      = "ZZZ_Monitor_Attr_" STR_SUBJECT_ATTRIBUTE "_List"
const string STR_MONITOR_ATTRIBUTE_STRINGS[] = { "Unmodified in this session", "Modified in this session" }
const int    INT_MONITOR_ATTRIBUTE_VALUES[]  = { 0, 1 }
const int    INT_MONITOR_ATTRIBUTE_COLOURS[] = { realColor_Black, realColor_Red }

Module modCurr = module (obj)

//////////////////////////////////////
// Auxiliary Functions

Date getDateCurrentSession (Module mod)
{
    HistorySession histSession = null
    Date dtCurrSession = null
    
    for histSession in mod do
        { dtCurrSession = when (histSession) }
    
    return dtCurrSession
}

string checkCreateMonitorAttr (string strAttrName)
{    
    if (!exists (attribute (strAttrName)))
    {
        string errorMsg = null
        
        setRealColorOptionForTypes (true)
        
        AttrType atMonitor = find (current Module, STR_MONITOR_ATTRIBUTE_TYPE)
        
        if (null atMonitor)
        {
            atMonitor = create (STR_MONITOR_ATTRIBUTE_TYPE, STR_MONITOR_ATTRIBUTE_STRINGS, INT_MONITOR_ATTRIBUTE_VALUES, INT_MONITOR_ATTRIBUTE_COLOURS, errorMsg)
            
            if (! null(errorMsg))
            {
                errorBox errorMsg
                halt
            }
        }
        
        AttrDef adMonitorAttr = create object hidden false inherit false type STR_MONITOR_ATTRIBUTE_TYPE attribute STR_MONITOR_ATTRIBUTE
        if (BL_DEBUG)
        { print "DEBUG: created monitor attribute\n" }
    }
    
    if (exists (attribute (strAttrName)))
    {
        if (BL_DEBUG)
        { print "DEBUG: monitor attribute already exists\n" }
        return ""
    }
    else
    {
        return "Failed to create the monitor attribute."
    }
}

string checkDeleteMonitorAttr (string strAttrName)
{
    AttrDef ad = find (current Module, strAttrName)
    
    string strErrorMsg = null
    
    if (!null ad)
        { strErrorMsg = delete (current Module, ad) }
    
    return strErrorMsg
}

bool lastModifiedInThisSession (string strAttrName, Date dateModOpened)
{
    History histObj
    HistoryType histType
    
    Date dateHistObj = null
    string strAttrMod = null
    
    bool blRetVal = false
    
    for histObj in obj do
    {
        histType = histObj.type
        dateHistObj = histObj.date
        
        if (histType == modifyObject)
        {
            strAttrMod = histObj.attrName
            
            if ((strAttrMod == STR_SUBJECT_ATTRIBUTE)&&(dateHistObj>dateModOpened))
            {
                if (BL_DEBUG)
                    { print "(" (identifier obj) " @ " (dateAndTime dateHistObj) ") " STR_SUBJECT_ATTRIBUTE ": " histObj.plainOldValue " -> " histObj.plainNewValue "\n" }
                
                obj.STR_MONITOR_ATTRIBUTE = STR_MONITOR_ATTRIBUTE_STRINGS[1] // "Modified in this session"
                blRetVal = true
                break
            } else {
                obj.STR_MONITOR_ATTRIBUTE = STR_MONITOR_ATTRIBUTE_STRINGS[0] // "Unmodified in this session"
                blRetVal = false
            }                
        }
    }

return blRetVal
}

//////////////////////////////////////
// DB/DBE Callback Functions


//////////////////////////////////////
// Main Program

if (!isEdit (modCurr))
{
    errorBox "Unable to continue - module must be open in exclusive edit mode to create/update the monitor attribute."
    halt
}

string strErrorMsg = null

strErrorMsg = checkCreateMonitorAttr (STR_MONITOR_ATTRIBUTE)

if (null strErrorMsg)
    {
        bool blModdedThisSession = lastModifiedInThisSession (STR_SUBJECT_ATTRIBUTE, (getDateCurrentSession (modCurr)))
        if (BL_DEBUG) print blModdedThisSession
    }
else
    {
        errorBox strErrorMsg
        halt
    }

 

Re: Highlight an enumeration attribute cell (text or background)
llandale - Sat Sep 26 17:14:18 EDT 2015

Wow.  I posted that trigger template years ago, glad to see at least one person uses it.

I had trouble following Richard's solution but his narrative is sound and I have no reason to suspect it won't work.

Have another idea.  Have a simple Attr-DXL, lets call that attribute "Highlighted", type "Enumerated" with two values "." and "HIGHLIGHTED".  The "color" of "." is black, the color of "HIGHLIGHTED" is red.

  • obj.attrDXLName = "."

At line 28 in your trigger code insert this:

  • obj./"Highlighted/" = \"HIGHLIGHTED\";

A column that contains one of your "Variant Status" attributes can define its color to be based on the "Highlighted" attribute.  Or, you could just also display the "Highlighted" attribute in your view.

-Louie

The basic idea here is that the attr-DXL will set its own result to "." only if it has no current value.  The trigger will set it to Highlighted regardless and it won't matter if the attr-DXL is in the view (already calculated) or not displayed (not already calculated); a "Highlighted" value won't get overwritten by a period unless you close the module or refresh dxl attributes.  Yes, it is OK to set an attr-DXL value from other code.